package com.oamicnet.boot.mybatis.controller;

import com.oamicnet.boot.mybatis.entity.Teacher;
import com.oamicnet.boot.mybatis.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/teacher")
public class TeacherController {

    @Autowired
    public TeacherService teacherService;

    @GetMapping("/{id}")
    public Teacher getTeacherById(@PathVariable Long id) {
        return teacherService.get(id);
    }

    @GetMapping
    public List<Teacher> getTeachers() {
        return teacherService.findAll();
    }

    @PostMapping
    public void saveTeacher(@RequestBody Teacher teacher) {
        teacherService.save(teacher);
    }

    @PutMapping
    public void updateTeacher(@RequestBody Teacher teacher) {
        teacherService.update(teacher);
    }

    @DeleteMapping
    public void deleteTeacher(Long id) {
        teacherService.delete(id);
    }
}
